﻿using System.Windows;
using System.Windows.Browser;
using HelloWorld.Shared.Models;

namespace HelloWorld
{
    /// <summary>
    /// Expose the Eat and Doit controls using public member variables
    /// </summary>
    [ScriptableType]    
    public partial class Demo4
    {
        private readonly MainPageModel _model = new MainPageModel();

        public Demo4()
        {
            InitializeComponent();
            DataContext = _model;
        }

        /// <summary>
        /// Gets the Eat control for javascript manipulation
        /// </summary>
        public System.Windows.Controls.RadioButton EatControl
        {
            get
            {
                return Eat;
            }
        }

        /// <summary>
        /// Gets the doit control for javascript manipulation
        /// </summary>
        public System.Windows.Controls.Button DoitControl
        {
            get
            {
                return Doit;
            }
        }

        /// <summary>
        /// Gets the result control for javascript manipulation
        /// </summary>
        public System.Windows.Controls.TextBlock ResultControl
        {
            get
            {
                return result;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            _model.Doit();
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            // Tell the browser that it can interact with this page
            HtmlPage.RegisterScriptableObject("Sample", this);
        }
    }
}
